package logic

import (
	"context"

	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysMenuListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysMenuListLogic {
	return &SysMenuListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysMenuListLogic) SysMenuList(in *sys.SysMenuListReq) (*sys.SysMenuListRes, error) {

	all, err := l.svcCtx.SysMenuModel.List(l.ctx)
	if err != nil {
		return nil, err
	}

	var list []*sys.SysMenuInfoRes
	for _, v := range all {
		list = append(list, &sys.SysMenuInfoRes{
			MenuId:      v.MenuId,
			ParentId:    v.ParentId,
			Name:        v.Name,
			Component:   v.Component,
			IsLink:      v.IsLink == 1,
			MenuSort:    v.MenuSort,
			Path:        v.Path,
			Redirect:    v.Redirect,
			Title:       v.Title,
			Icon:        v.Icon,
			IsHide:      v.IsHide == 1,
			IsKeepAlive: v.IsKeepAlive == 1,
			IsAffix:     v.IsAffix == 1,
			LinkUrl:     v.LinkUrl,
			MenuType:    v.MenuType,
			IsIframe:    v.IsIframe == 1,
		})
	}

	return &sys.SysMenuListRes{
		List: list,
	}, nil
}
